/***************************************************************************
 *   Copyright (c) 2015 Eivind Kvedalen <eivind@kvedalen.name>             *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 51 Franklin Street,      *
 *   Fifth Floor, Boston, MA  02110-1301, USA                              *
 *                                                                         *
 ***************************************************************************/

#include "pch.h"


#include "Gui/Command.h"
#include "ExpressionBinding.h"
// #include "QuantitySpinBox_p.h"

#include "App/Application.h"
#include <App/Document.h>

// #include <App/Expression.h>
// #include <App/ObjectIdentifier.h>
#include <Base/Tools.h>


FC_LOG_LEVEL_INIT("Expression",true,true)

using namespace Gui;
using namespace App;
namespace bp = boost::placeholders;

ExpressionBinding::ExpressionBinding()
    : iconLabel(nullptr)
    , iconHeight(-1)
    , m_autoApply(false)
{
}


ExpressionBinding::~ExpressionBinding()
{
}

bool ExpressionBinding::isBound() const{return 0;}

void ExpressionBinding::unbind()
{
    expressionchanged.disconnect();
    objectdeleted.disconnect();
    path = int();
}

void Gui::ExpressionBinding::setExpression(std::shared_ptr<Expression> expr){return ;}

void ExpressionBinding::bind(const int &_path){}



bool ExpressionBinding::hasExpression() const
{
    return isBound() && getExpression() != nullptr;
}

std::shared_ptr<App::Expression> ExpressionBinding::getExpression() const{return nullptr;}

std::string ExpressionBinding::getExpressionString(bool no_throw) const{return "";}

std::string ExpressionBinding::getEscapedExpressionString() const
{
    return Base::Tools::escapedUnicodeFromUtf8(getExpressionString(false).c_str());
}

QPixmap ExpressionBinding::getIcon(const char* name, const QSize& size) const
{
    QString key = QString::fromLatin1("%1_%2x%3")
        .arg(QString::fromLatin1(name))
        .arg(size.width())
        .arg(size.height());
    QPixmap icon;
    if (QPixmapCache::find(key, &icon))
        return icon;


    if (!icon.isNull())
        QPixmapCache::insert(key, icon);
    return icon;
}

bool ExpressionBinding::apply(const std::string & propName){return 0;}

bool ExpressionBinding::apply(){return 0;}

void ExpressionBinding::expressionChange(const int& id) {

    if(id==path)
        onChange();
}

void ExpressionBinding::objectDeleted(const App::DocumentObject& obj){}

void ExpressionBinding::makeLabel(QLineEdit* le){}
